//map.js
//获取应用实例
const app = getApp()

Page({
  data: {
    longitude: 104,
    latitude: 30,
    markers: [],
    circles: [],
    controls: [{
      id: 1,
      iconPath: '/resources/location.png',
      position: {
        left: 0,
        top: 300 - 50,
        width: 50,
        height: 50
      },
      clickable: true
    }]
  },
  //事件处理函数
  bindViewTap: function () {

  },
  onLoad: function () {
    var that = this
    wx.showLoading({
      title: "定位中",
      mask: true
    })
    // 定位当前位置
    wx.getLocation({
      type: 'gcj02',
      altitude: true,//高精度定位
      //定位成功，更新定位结果
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        var speed = res.speed
        var accuracy = res.accuracy
        that.setData({
          longitude: longitude,
          latitude: latitude,
          markers: [
            {
              id: 0,
              latitude: res.latitude,
              longitude: res.longitude,
              width: 50,
              height: 50,
            },
            {
              id: 1,
              latitude: res.latitude-0.1,
              longitude: res.longitude-0.1,
              width: 50,
              height: 50,
            },
            {
              id: 2,
              latitude: res.latitude-0.1,
              longitude: res.longitude,
              width: 50,
              height: 50,
            },
          ],
          circles: [{
            latitude: res.latitude,
            longitude: res.longitude,
            color: '#FF0000DD',
            fillColor: '#7cb5ec88',
            radius: 3000,
            strokeWidth: 1
          }]
        })
      },
      //定位失败回调
      fail: function () {
        wx.showToast({
          title: "定位失败",
          icon: "none"
        })
      },

      complete: function () {
        //隐藏定位中信息进度
        wx.hideLoading()
      }

    })
  },
  markertap(e) {
    console.log(e.markerId)
  },
  controltap(e) {
    console.log(e.controlId)
  }
})
